package com.itboye.lottery.fragment.home

import android.content.Intent
import android.view.View
import com.itboye.lottery.base.BaseFragment
import com.itboye.lottery.R
import com.itboye.lottery.adapter.HomeLotteryClassificationAdapter
import com.itboye.lottery.bean.LotteryClassificationBean
import kotlinx.android.synthetic.main.fragment_lottery_classification.*
import android.os.Bundle
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
import com.itboye.lottery.activity.daletou.BascketballMainActivity
import com.itboye.lottery.activity.daletou.DaLeTouMainActivity
import com.itboye.lottery.activity.football.FootballMainActivity
import com.itboye.lottery.activity.shuangseqiu.ShuangSeQiuMainActivity
import com.itboye.lottery.bean.IndexDataBean


/**
 * Created by Administrator (IntelliJ IDEA) on 2018/7/2.
 * @description: Lottery
 *
 */
class LotteryClassificationFragment : BaseFragment() {

    companion object {
        fun newInstance(fragmentArrayList: List<IndexDataBean.Caizhong>): LotteryClassificationFragment {
            val fragment = LotteryClassificationFragment()
            val bundle = Bundle()
            var ar = ArrayList<IndexDataBean.Caizhong>()
            fragmentArrayList.forEachIndexed { index, lotteryClassificationBean ->
                ar.add(lotteryClassificationBean)
            }
            bundle.putSerializable("array", ar)
            fragment.arguments = bundle
            return fragment
        }
    }

    private lateinit var lotteryClassificationBeanArray: ArrayList<IndexDataBean.Caizhong>

    override fun getLayoutId(): Int {
        return R.layout.fragment_lottery_classification
    }

    override fun initData() {
        lotteryClassificationBeanArray = arguments!!.getSerializable("array") as ArrayList<IndexDataBean.Caizhong>
        setData(lotteryClassificationBeanArray)
    }

    override fun onClick(p0: View?) {
    }

    private lateinit var homeClassfyAdapter: HomeLotteryClassificationAdapter


    fun setData(lotteryClassificationBeanArray: java.util.ArrayList<IndexDataBean.Caizhong>) {
        homeClassfyAdapter = HomeLotteryClassificationAdapter(lotteryClassificationBeanArray)
        homeClassfyAdapter.setOnItemClickListener({ view, position ->
            when (position) {
                0 -> {
                    startActivity(Intent(activity, ShuangSeQiuMainActivity::class.java))
                }
                1 -> {
                    startActivity(Intent(activity, DaLeTouMainActivity::class.java))
                }
                2 -> {
                    startActivity(Intent(activity, FootballMainActivity::class.java))
                }
                3 -> {
                    startActivity(Intent(activity, BascketballMainActivity::class.java))
                }
                else -> {
                }
            }
        })
        rv_lottery_classification.layoutManager = GridLayoutManager(activity, 4) as RecyclerView.LayoutManager?
        rv_lottery_classification.adapter = homeClassfyAdapter
        rv_lottery_classification.isNestedScrollingEnabled = true
        rv_lottery_classification.adapter = homeClassfyAdapter
    }

}